<template>
	<div class="edit-popup">
		<popup ref="popupRef" title="上传凭证" :async="true" width="550px" @confirm="handleSubmit"
			@close="handleClose">
<el-form ref="formRef" :model="formData" label-width="120px">
                <el-form-item label="凭证" prop="service_voucher">
                    <div>
                        <material-picker v-model="formData.service_voucher" :limit="5"/>
                    </div>
                </el-form-item>
				
			</el-form>
		</popup>
	</div>
</template>

<script lang="ts" setup>
	import { refundSet } from '@/api/finance'
	import {uploadServerVoucher} from '@/api/app/recharge'
	import type { FormInstance, FormRules } from 'element-plus'
		import Popup from '@/components/popup/index.vue'
		import type { PropType } from 'vue'
		
	defineProps({
		dictData: {
			type: Object as PropType<Record<string, any[]>>,
			default: () => ({})
		}
	})
	const emit = defineEmits(['success', 'close'])
	const formRef = shallowRef<FormInstance>()
	const popupRef = shallowRef<InstanceType<typeof Popup>>()
	const mode = ref('add')

	const formData = reactive({
		id: '',
		service_voucher:''
	})
	// 获取详情
	const setFormData = async (data : Record<any, any>) => {
		for (const key in formData) {
			if (data[key] != null && data[key] != undefined) {
				//@ts-ignore
				formData[key] = data[key]
			}
		}
	}
	// 提交按钮
	const handleSubmit = async () => {
		await formRef.value?.validate()
		const data = { ...formData, }
		console.log(data)
		await uploadServerVoucher({
			id:data.id,
			service_voucher:data.service_voucher
		})
		popupRef.value?.close()
		emit('success')
	}
	
	//打开弹窗
	const open = (type = 'add') => {
		mode.value = type
		popupRef.value?.open()
	}
	
	// 关闭回调
	const handleClose = () => {
		emit('close')
	}
	
	
	
	defineExpose({
		open,
		setFormData,
	})
</script>